package web;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Date;

@WebServlet("/ServletContextDemo1")
public class ServletContextDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1，通过Servlet对象获取  this = httpServlet
        ServletContext app1 = this.getServletContext();
        System.out.println(app1);
        //2.通过请求对象request获取
        ServletContext app2 = request.getServletContext();
        System.out.println(app2);
        System.out.println(app1==app2);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().write(new Date().toString());
    }
}
